<template>
	<div>
		<el-card shadow="hover">
			<div class=" mb15">
				<el-form :model="tableData.param" ref="queryRef" :inline="true" label-width="100px">
					<el-row>
						<el-col :span="8" >
							<el-form-item label="企业名称" prop="companyName">
								<el-input v-model="tableData.param.companyName" placeholder="请输入企业名称" clearable
									@keyup.enter.native="getList" />
							</el-form-item>
						</el-col>
						

						<el-col :span="8" >
							<el-form-item>
								<el-button type="primary" @click="getList"><el-icon>
										<Search />
									</el-icon>搜索</el-button>
								<el-button @click="resetQuery(queryRef)"><el-icon>
										<Refresh />
									</el-icon>重置</el-button>
								<el-button type="primary" @click="exportFile" v-if="permissionStore.isPermissionsBtn('009002001')"><el-icon>
									<Download />
								</el-icon> 导出</el-button>
							</el-form-item>
						</el-col>
						
					</el-row>
					
				</el-form>
			</div>
			<el-table v-loading="loading" :data="tableData.data">
				<el-table-column label="企业名称" align="center" prop="companyName" min-width="100px" />
				<el-table-column label="累计充值金额" align="center" prop="totalAmount" min-width="100px" />
				<el-table-column label="剩余金额" align="center" prop="balance" min-width="100px" />
				<el-table-column label="操作" min-width="100px" align="center" v-if="permissionStore.isPermissionsBtn('009002002')">
              <template #default="scope">
                <el-button size="small" text type="success" @click="handleView(scope.row)"><el-icon>
								<View />
							</el-icon>详情</el-button>
              </template>
            </el-table-column>
			</el-table>
			<pagination v-show="tableData.total > 0" :total="tableData.total" v-model:page="tableData.param.pageNumber"
				v-model:limit="tableData.param.pageLength" @pagination="getList" />
		</el-card>
		<detailView ref="detailRef"></detailView>
	</div>
</template>
<script lang="ts">
import {  companyAmountListApi} from '@/api/financeCenter/financeManage/index';
import { toRefs, reactive, onMounted, ref, defineComponent, computed, getCurrentInstance, toRaw } from 'vue';
import { FormInstance } from 'element-plus';
import { getFile } from '@/utils/excel/excelUtil'
import { usePermissionStore } from "@/store/modules/permission"
import detailView from './component/detail.vue'
export default defineComponent({
	name: 'financeManageList',  //订单列表
	components:{detailView},
	setup() {
		const { proxy } = <any>getCurrentInstance();
		const loading = ref(false);
		const queryRef = ref();
		const detailRef=ref();
		const permissionStore = usePermissionStore()
		const state = reactive({
			tableData: {
				data: [],
				total: 0,
				loading: false,
				param: {
					pageNumber: 1,
					pageLength: 10,
					companyName: undefined,
				},
			},
		});
		// 页面加载时
		onMounted(() => {
			initTableData();
		});
		// 初始化表格数据
		const initTableData = () => {
			getList();
		};
		/** 重置按钮登录 */
		const resetQuery = (formEl: FormInstance | undefined) => {
			if (!formEl) return;
			formEl.resetFields();
			getList();
		};
		// 获取列表数据
		const getList = () => {
			loading.value = true;
			companyAmountListApi(state.tableData.param).then((res: any) => {
				let list = res.data.list ?? [];
				state.tableData.data = list
				console.log(state.tableData.data);
				state.tableData.total = res.data.total;
				loading.value = false;
			});
		};
		const handleView = (row) => {
			detailRef.value.openDialog(toRaw(row));
		};
		// 导出文件
		const exportFile = async () => {
			getFile('/system/company/amount/list/export','财务数据')
		}
		return {
			proxy,
			loading,
			queryRef,
			detailRef,
			resetQuery,
			getList,
			exportFile,
			handleView,
			permissionStore,
			...toRefs(state),
		};
	},
});
</script>
<style lang="scss" scoped>
.colBlock {
	display: block;
}

.colNone {
	display: none;
}
</style>
